//
//  ViewController.m
//  serviceTest
//
//  Created by glendale on 13-7-27.
//  Copyright (c) 2013年 glendale. All rights reserved.
//

#import "AddServiceViewController.h"
#import "PanelScrollView.h"
#import "MyAFNetWorkManager.h"
#import "SVProgressHUD.h"
#import "UIImageView+WebCache.h"
#import "SDWebImageDownloader.h"

@interface AddServiceViewController ()
{
    NSArray *imgArr1;
    NSArray *imgArr2;
    NSArray *imgArr3;
    NSArray *imgArr4;
    NSArray *imgArr5;
}

@end

@implementation AddServiceViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
    
    panelView = [[UIView alloc] initWithFrame:CGRectMake(100, 200, 1024, 400)];
    [self.view addSubview:panelView];
    
    
    if (self.detailType==TypeZengzhi) {
        [self requestImgWithSecondID:@"61661001" andBtnNumber:1];
        [self requestImgWithSecondID:@"61661001" andBtnNumber:2];
        [self requestImgWithSecondID:@"61661001" andBtnNumber:3];
        [self requestImgWithSecondID:@"61661001" andBtnNumber:4];
        [self requestImgWithSecondID:@"61661001" andBtnNumber:5];
    }
    else{
        self.btn1.hidden = YES;
        self.btn2.hidden = YES;
        self.btn3.hidden = YES;
        self.btn4.hidden = YES;
        self.btn5.hidden = YES;
        
        NSString *ID;
        switch (self.detailType) {
            case TypePinPai:
                self.titleLab.text = @"品牌故事";
                ID = @"61651002";
                break;
                
            case Type4S:
                self.titleLab.text = @"本店优势";
                ID = @"61651003";
                break;
                
            case TypeKeJi:
                self.titleLab.text = @"广汽科技";
                ID = @"61651005";
                break;
                
            case TypeZouJin:
                self.titleLab.text = @"走进广汽";
                ID = @"61651004";
                break;
            default:
                break;
        }
        
        [self requestImgWithFirstId:ID];
    }
}


- (void)viewWillAppear:(BOOL)animated
{
    //[self btnSelect:self.btn1];
}

- (void)requestImgWithFirstId:(NSString *)ID
{
    [MyAFNetWorkManager postWithParam:nil andAction:@"QUERY_ATTACHMENT_PICTURE" finish:^(NSData *data, NSDictionary *obj, NSError *error) {
        if (!error) {
            //NSLog(@"增值服务套餐展示%@",obj);
            PanelScrollView *scrollView = [[PanelScrollView alloc] initWithFrame:CGRectMake(0, 0, 1024, 400)];
            
            [scrollView.dataArray setArray:(NSArray *)obj[@"TT_ATTACHMENT_UPLOAD"]];
            
            [panelView addSubview:scrollView];
            
        }
        else{
            [SVProgressHUD showErrorWithStatus:error.localizedDescription];
        }
    }];
}


- (void)requestImgWithSecondID:(NSString *)ID andBtnNumber:(int)number
{
    [MyAFNetWorkManager postWithParam:@{@"FUNCTION_TYPE":[NSString stringWithFormat:@"61651001"],@"SECOND_FUNCTION_TYPE":ID} andAction:@"QUERY_ATTACHMENT_PICTURE" finish:^(NSData *data, NSDictionary *obj, NSError *error) {
        if (!error) {
            NSLog(@"增值服务套餐展示%@",obj);
            
            switch (number) {
                case 1:
                    imgArr1 = obj[@"TT_ATTACHMENT_UPLOAD"];
                    break;
                    
                case 2:
                    imgArr2 = obj[@"TT_ATTACHMENT_UPLOAD"];
                    break;
                    
                case 3:
                    imgArr3 = obj[@"TT_ATTACHMENT_UPLOAD"];
                    break;
                    
                case 4:
                    imgArr4 = obj[@"TT_ATTACHMENT_UPLOAD"];
                    break;
                    
                case 5:
                    imgArr5 = obj[@"TT_ATTACHMENT_UPLOAD"];
                    break;
                default:
                    break;
            }
            
        }
        else{
            [SVProgressHUD showErrorWithStatus:error.localizedDescription];
        }
        
    }];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)btnSelect:(UIButton *)sender {
    
    [sender setBackgroundImage:[UIImage imageNamed:@"AllAuto_Button_Items_Select_BG@2x"] forState:UIControlStateNormal];
    
    [sender setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];

    for (UIView *view in [panelView subviews]) {
        [view removeFromSuperview];
    }
//     NSArray *titAray= [NSArray arrayWithObjects:@"机油卡",@"机油卡",@"安心的服务保障",@"亲切贴心的服务举措",@"确实可靠的维修技术",@"迅速高效的应对能力",@"保养结算说明",@"结算说明手册",@"辅助看板", nil];
    PanelScrollView *scrollView = [[PanelScrollView alloc] initWithFrame:CGRectMake(0, 0, 1024, 400)];
    
    
    if (sender==self.btn1) {
        [scrollView.dataArray setArray:imgArr1];
        scrollView.titleArrey = [NSArray arrayWithObject:@"辅助看板"];
        scrollView.typeArray = [NSArray arrayWithObject:@"jpg"];
        
        [self.btn2 setBackgroundImage:[UIImage imageNamed:@"AllAuto_Button_Items_Unselect_BG@2x"] forState:UIControlStateNormal];
        [sender setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [self.btn3 setBackgroundImage:[UIImage imageNamed:@"AllAuto_Button_Items_Unselect_BG@2x"] forState:UIControlStateNormal];
        [sender setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [self.btn4 setBackgroundImage:[UIImage imageNamed:@"AllAuto_Button_Items_Unselect_BG@2x"] forState:UIControlStateNormal];
        [sender setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [self.btn5 setBackgroundImage:[UIImage imageNamed:@"AllAuto_Button_Items_Unselect_BG@2x"] forState:UIControlStateNormal];
        [sender setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    }
        
    if (sender==self.btn2) {
        
        [scrollView.dataArray setArray:imgArr2];
        scrollView.titleArrey =  [NSArray arrayWithObjects:@"机油卡",@"机油卡",nil];
        scrollView.typeArray = [NSArray arrayWithObjects:@"jpg", @"jpg",nil];
        
        [self.btn1 setBackgroundImage:[UIImage imageNamed:@"AllAuto_Button_Items_Unselect_BG@2x"] forState:UIControlStateNormal];
        [sender setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [self.btn3 setBackgroundImage:[UIImage imageNamed:@"AllAuto_Button_Items_Unselect_BG@2x"] forState:UIControlStateNormal];
        [sender setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [self.btn4 setBackgroundImage:[UIImage imageNamed:@"AllAuto_Button_Items_Unselect_BG@2x"] forState:UIControlStateNormal];
        [sender setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [self.btn5 setBackgroundImage:[UIImage imageNamed:@"AllAuto_Button_Items_Unselect_BG@2x"] forState:UIControlStateNormal];
        [sender setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    }
    
   
    
    if (sender==self.btn3) {
        [scrollView.dataArray setArray:imgArr3];
        scrollView.titleArrey =  [NSArray arrayWithObjects:@"机油卡",@"机油卡",nil];
        scrollView.typeArray = [NSArray arrayWithObjects:@"jpg", @"jpg",nil];
        
        [self.btn2 setBackgroundImage:[UIImage imageNamed:@"AllAuto_Button_Items_Unselect_BG@2x"] forState:UIControlStateNormal];
        [sender setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [self.btn1 setBackgroundImage:[UIImage imageNamed:@"AllAuto_Button_Items_Unselect_BG@2x"] forState:UIControlStateNormal];
        [sender setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [self.btn4 setBackgroundImage:[UIImage imageNamed:@"AllAuto_Button_Items_Unselect_BG@2x"] forState:UIControlStateNormal];
        [sender setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [self.btn5 setBackgroundImage:[UIImage imageNamed:@"AllAuto_Button_Items_Unselect_BG@2x"] forState:UIControlStateNormal];
        [sender setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    }
    
    if (sender==self.btn4) {
        
        [scrollView.dataArray setArray:imgArr4];
        scrollView.titleArrey = [NSArray arrayWithObject:@"结算说明手册"];
        scrollView.typeArray = [NSArray arrayWithObject:@"pdf"];
        
        [self.btn2 setBackgroundImage:[UIImage imageNamed:@"AllAuto_Button_Items_Unselect_BG@2x"] forState:UIControlStateNormal];
        [sender setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [self.btn3 setBackgroundImage:[UIImage imageNamed:@"AllAuto_Button_Items_Unselect_BG@2x"] forState:UIControlStateNormal];
        [sender setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [self.btn1 setBackgroundImage:[UIImage imageNamed:@"AllAuto_Button_Items_Unselect_BG@2x"] forState:UIControlStateNormal];
        [sender setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [self.btn5 setBackgroundImage:[UIImage imageNamed:@"AllAuto_Button_Items_Unselect_BG@2x"] forState:UIControlStateNormal];
        [sender setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    }
    if (sender==self.btn5) {
        [scrollView.dataArray setArray:imgArr5];
        [scrollView.dataArray setArray:imgArr4];
        scrollView.titleArrey = [NSArray arrayWithObject:@"结算说明手册"];
        scrollView.typeArray = [NSArray arrayWithObject:@"pdf"];
        
        [self.btn2 setBackgroundImage:[UIImage imageNamed:@"AllAuto_Button_Items_Unselect_BG@2x"] forState:UIControlStateNormal];
        [sender setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [self.btn3 setBackgroundImage:[UIImage imageNamed:@"AllAuto_Button_Items_Unselect_BG@2x"] forState:UIControlStateNormal];
        [sender setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [self.btn4 setBackgroundImage:[UIImage imageNamed:@"AllAuto_Button_Items_Unselect_BG@2x"] forState:UIControlStateNormal];
        [sender setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [self.btn1 setBackgroundImage:[UIImage imageNamed:@"AllAuto_Button_Items_Unselect_BG@2x"] forState:UIControlStateNormal];
        [sender setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    }
    
    [scrollView resetImg];
    [panelView addSubview:scrollView];
}

- (IBAction)backBtn:(id)sender {
    
    [self.navigationController popViewControllerAnimated:YES];
}

- (IBAction)homeBtn:(id)sender {
    [self.navigationController popToRootViewControllerAnimated:YES];
}
@end
